namespace 项目01;
class Student
{
    public string name;
    public string id;
    public string gender;
    private int age;

    public int Age
    {
        get => age;
        set
        {
            if (value < 1 || value > 150)
            {
                age = 0;
            }
            else
            {
                age = value;
            }

        }

    }
    public phone Phone;

    public string GetInof()
    {
        return $"姓名：{name}\n身份证：{id}\n性别：{gender}\n年龄：{age}\n手机型号:{Phone.型号}\n手机号码:{Phone.号码}";
    }

    public Student(string 姓名, string 身份证, string 手机型号, string 手机号码)
    {
        name = 姓名;
        id = 身份证;
        // gender = 获取身份证信息().性别;
        // age = 获取身份证信息().年龄;
        获取身份证信息();
        Phone = new phone(姓名, 手机型号, 手机号码);
    }

    // public (string 性别, int 年龄) 获取身份证信息()
    // {
    //     int 身份证倒数第2位 = id[16];
    //     string gender = 身份证倒数第2位 % 2 == 0 ? "女" : "男";
    //     DateTime today = DateTime.Now;
    //     string year = id[6..10];
    //     string month = id[10..12];
    //     string day = id[12..14];
    //     DateTime birthday = DateTime.Parse($"{year}-{month}-{day}");
    //     int age = today.Year - birthday.Year;
    //     if(today.Month<birthday.Month) age--;
    //     if((today.Month==birthday.Month)&&(today.Date<birthday.Date)) age--;
    //     return (gender,age);
    // }
    public void 获取身份证信息()
    {
        int 身份证倒数第2位 = id[16];
        string gender = 身份证倒数第2位 % 2 == 0 ? "女" : "男";
        DateTime today = DateTime.Now;
        string year = id[6..10];
        string month = id[10..12];
        string day = id[12..14];
        DateTime birthday = DateTime.Parse($"{year}/{month}/{day}");
        int age = today.Year - birthday.Year;
        if (today.Month < birthday.Month) age--;
        if ((today.Month == birthday.Month) && (today.Date < birthday.Date)) age--;

    }
}